﻿/*
* ////////////////////////////////////////////////
*
* 开发者：AZPEP
* 友情链接：
*	-	B站：		零分的考卷			https://space.bilibili.com/257391258
*	-	Github：	AZPEP-BiliBili		https://github.com/AZPEP-BiliBili
*	-	Gitee：		AZPEP_BiliBili		https://gitee.com/AZPEP_BiliBili
*
* CopyRight AZPEP
*
* ////////////////////////////////////////////////
*/

#include "pch.h"
#include "GetESP.h"
#include "GetGpt.h"

const GUID PARTITION_SYSTEM_GUID = { 0xC12A7328, 0xF81F, 0x11D2, {0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B } }; //ESP分区类型的GUID

/// <summary>
/// 获取计算机上所有的EFI分区
/// </summary>
/// <param name="EspInformation">指向存放EFI分区信息指针的列表指针</param>
/// <returns>成功返回0，EspInformation指向存放EFI分区信息指针的列表；失败返回GetLastError()获取的错误代码，EspInformation为空列表</returns>
DWORD MountEsp_GetEfiPartitionInfoW(
	_Out_ std::vector<PartitionInformationW*>* EspInformation
) {
	DWORD dStatus;

	std::vector<PartitionInformationW*> AllGptPartitionInfo;			//存放所有GPT分区信息
	dStatus = MountEsp_GetAllGptPartitionInformationW(
		&AllGptPartitionInfo
	);

	//获取失败，返回错误代码
	if (dStatus != 0) { return dStatus; }

	//开始遍历获取EFI分区
	for (int i = 0; i < AllGptPartitionInfo.size(); i++) {
		PartitionInformationW* _PIW = AllGptPartitionInfo[i];

		//是EFI分区，推入
		if (_PIW->PartitionType == PARTITION_SYSTEM_GUID) { EspInformation->push_back(_PIW); }
	}

	//获取成功，返回
	return 0;
}